const initState = {
  musicInfo: null, // 歌曲信息: { songId: 0, songName: '', picUrl: '', duration: 0, artists: [] }
  musicUrlData: null, // 歌曲url
  isPlay: false, // 是否播放
  volume: 30 / 100, // 音量
  isMute: false, // 是否静音
  playMode: '0', // 播放模式: '0'随机播放, '1'列表循环, '2'单曲循环
  currentTime: 0, // 获取的当前歌曲播放时长
  _currentTime: 0, // 设置当前歌曲播放时长
}

function musicReducer(state = initState, action) {
  switch (action.type) {
    case 'music_url': 
      state.musicInfo = action.data.musicInfo
      state.musicUrlData = action.data.musicUrl
      break;
    case 'music_init':
      state.isPlay = true
      break;
    case 'play_mode': 
      state.playMode = action.data
      break;
    case 'is_play':
      state.isPlay = !state.isPlay
      break;
    case 'music_volume':
      state.volume = action.data
      break;
    case 'get_duration':
      state.currentTime = action.data
      break;
    case 'set_duration':
      state._currentTime = action.data
      break;
    default: return {...state}
  }
  return {...state} // 直接返回state不会触发组件重新渲染，需要更改state的引用地址
}

export default musicReducer